package com.yingxin.yxerp.module.dingtalk.controller;

import com.yingxin.yxerp.module.dingtalk.service.PdfService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "pdf转换")
@RestController
@RequestMapping("/pdf/manage")
public class PdfController{

    @Autowired
    private PdfService pdfService;

    @PostMapping("/create")
    public void create() {

        // 模板中的数据，实际运用从数据库中查询
        Map<String,Object> data = new HashMap<>();
        List<Map<String, String>> dataList = new ArrayList<>();
        for ( int i = 0; i < 20; i++ ) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("c1","20220927");
            itemMap.put("c2","跨行转入");
            itemMap.put("c3","999");
            itemMap.put("c4","13123123");
            itemMap.put("c5",String.valueOf(1000 + i));
            itemMap.put("c6","0.00");
            itemMap.put("c7","贷");
            itemMap.put("c8","31312.00");
            dataList.add(itemMap);
        }
        data.put("dataList", dataList);

        String fileName = pdfService.htmlToPdf( data, "duxinPriceTablePdf.ftl" );
    }

}
